package com.feiyuan.helper;

import com.feiyuan.modules.sys.entity.DictTabulateEntity;
import com.feiyuan.modules.sys.mapper.DictTabulateDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

@Configuration
public class ApplicationContextHelperRun {

    private Logger logger = LoggerFactory.getLogger(ApplicationContextHelperRun.class);

    @Autowired
    private ApplicationContext context;

    @Autowired
    private DictTabulateDao dictTabulateDao;

    @PostConstruct
    public void init() {
        Map<String, HelperInterface> beans = context.getBeansOfType(HelperInterface.class);
        logger.info("this is beans {}", beans);
        beans.values().forEach(item -> {
            String key = item.getKey();
            logger.info("key:{}", key);
            List<DictTabulateEntity> lists = dictTabulateDao.selectTabulates(key);
            logger.info("lists:{}", lists);
            item.updateProfile(lists);
        });
    }
}
